package com.yhp.dao.impl;

import com.yhp.bean.Users;
import com.yhp.dao.DBUtils;
import com.yhp.dao.UsersDao;
import java.sql.SQLException;
import java.util.ArrayList;

public class UsersDaoImple extends DBUtils implements UsersDao {

    @Override
    public Users longin(String username, String userpassword) {
        Users users = null;
        try {
         String sql = "select * from users where loginname=? and password=?";
        ArrayList arrayList = new ArrayList();
        arrayList.add(username);
        arrayList.add(userpassword);
        resultSet = query(sql,arrayList);
       System.out.println("取出数据库内容："+resultSet);
       if (resultSet==null){ return null;}//对空的时候进行处理！！！
       if (resultSet.next()){
           users = new Users();//想重新写入要重洗！！！
             users.setLoginname(username);
             users.setRealname(resultSet.getString("realname"));
             users.setUserid(resultSet.getInt("userid"));
       }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }
        return users;
    }
}
